test: Use sphinx.ext.doctest for doctesting#625
Open
ValerianRey wants to merge 9 commits intomainfrom
Open
Conversation
f4eff77 to
bf59f4a
Compare
| Import several classes from ``torch`` and ``torchjd``: | ||
|
|
||
| .. code-block:: python | ||
| .. testcode:: |
Contributor
There was a problem hiding this comment.
Does this change the way it looks?
Contributor
Author
There was a problem hiding this comment.
Does this change the way it looks?
I don't remember. It looks good at least, and doesn't change much. I'll compare later today or tomorrow.
PierreQuinton
approved these changes
Mar 7, 2026
Contributor
PierreQuinton
left a comment
There was a problem hiding this comment.
Very nice, didn't check the way code looks in the doc, but otherwise LGTM
Contributor
Author
|
Something I forgot to mention is that by default (i.e. "default"), the python code that is after We could also disable this + use .. doctest:: directives for these examples, so that we're able to decide which of them to test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The idea is to use
sphinx.ext.doctestto be able to run examples and check their output.I think we tried that a very long time ago, but we had two issues:
emphasize-linesoption to it. A more long-term solution would be to contribute this change directly to the sphinx repo, by fixing Add :caption: for .. doctest:: sphinx-doc/sphinx#6915 and testcode directives should support the same options as code-block sphinx-doc/sphinx#6858. But for now, it works.In a future step, I'd like to try to also test the examples from the README. I think we could import the entire README to some other place (like the main page of torchjd.org, to avoid having to maintain one). Then, it could be doctested when we run
uv run make doctest -C docs. So this would solve two problems at once. But this is out of the scope of this PR, as the README examples were never tested.Changes:
TODO before merging: change expected check from "Build documentation" to "Build and test documentation" in ruleset.